package com.ruoyi.customer.service;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.constant.PushRegistrationConstants;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.customer.api.domain.ZkxcUser;
import com.ruoyi.iot.api.RemoteIotService;
import com.ruoyi.iot.api.domain.PushInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;

@Service
public class PushRegistrationService {
    @Autowired
    private RemoteIotService remoteIotService;

    public void pushRegistration(ZkxcUser zkxcUser) {
        CompletableFuture.runAsync(() -> {
            PushInfo pushInfo = new PushInfo();
            pushInfo.setTopic(PushRegistrationConstants.PUSH_REGISTRATION_TOPIC);
            pushInfo.setPayload(JSONObject.toJSONString(zkxcUser).getBytes(StandardCharsets.UTF_8));
            remoteIotService.pushHandler(pushInfo, SecurityConstants.INNER);
        });
    }
}
